package sdmakerz_v1.coresyntax.generator

import java.util.ArrayList
import java.util.List
import sdmakerz_v1.coresyntax.sDMakerV1.Call
import sdmakerz_v1.coresyntax.sDMakerV1.Expression
import sdmakerz_v1.coresyntax.generator.interfaces.IMethodData
import sdmakerz_v1.coresyntax.generator.interfaces.IInputData
import sdmakerz_v1.coresyntax.SDMakerV1Utils

class MethodDataImpl implements IMethodData {
	private String methodName;
	private List<Call> calls;
	private List<String> paramsRealType;
	
	
    /* ****************** *
     * ** INITIALIZERS ** *
     * ****************** */
     
	override void init(IInputData inputData, Call model){
		calls= new ArrayList<Call>();
		paramsRealType= new ArrayList<String>();
		
		for(Expression exp : model.params){
			paramsRealType.add(SDMakerV1Utils::clazzQualifiedNameFromExp(inputData, exp))
		}
		
		methodName= model.name;
	}
	
	
	
    /* ************* *
     * ** SETTERS ** *
     * ************* */
     
     override void addCall(IInputData inputData, Call c){		
			this.calls.add(c);
	}
	
	def void setTypeOwner(String typeOwner){
		this.typeOwner= typeOwner;
	}
	
	def void setName(String name){
		this.name= name;
	}
    
    
    
    /* ************* *
     * ** GETTERS ** *
     * ************* */
     
    override String getMethodName(){
    	return methodName;
    }
    
	override List<String> getParamsRealType(){
		return paramsRealType;
	}	
	
	def String getParamType(int i){
		return paramsRealType.get(i);
	}
	
	def List<Call> getCalls(){
		return calls;
	}



    /* ************* *
     * ** TESTORS ** *
     * ************* */
     
	override boolean match(IInputData inputData, Call c) {
		var int i= 0;
		var boolean goodPreconditions= true;
		var boolean match= true;
		
		if(c.name.compareTo(methodName)!=0){
			goodPreconditions= false;
		}
		
		if(c.params.size != paramsRealType.size){
			goodPreconditions= false;
		}
		
		if(goodPreconditions){
			for(Expression exp : c.params){
			
				if(paramsRealType.get(i).compareTo(
				   	SDMakerV1Utils::clazzQualifiedNameFromExp(
				   		inputData, exp))==false){
					match= false;
				}
			
				i= i + 1;
			}	
		}
		else{
			match= false;
		}
		
		return match;
	}
}